﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Media.Imaging;

namespace WPFTest
{
    class DivImage : Div
    {
        protected System.Windows.Media.Imaging.BitmapSource ImageFrame;
        protected int index;

        public DivImage(System.Windows.Media.Imaging.BitmapSource ImageFrame,int i)
        {
            this.id = "class_image";
            this.ImageFrame = ImageFrame;
            index = i;
        }

        public override void WriteContent(TextWriter tw, string out_path)
        {
            tw.WriteLine("<div id='class_screenshot'>");
            tw.WriteLine("<img class='class_image' src='image_" + index.ToString() + ".png" + "' />");
            tw.WriteLine("</div>");
            tw.WriteLine("<hr></br>");
            SaveFrameToFile(out_path);
        }

        protected void SaveFrameToFile(string out_path)
        {
            FileStream fStream = new FileStream(out_path + "image_" + index.ToString() +".png", FileMode.Create);
            PngBitmapEncoder encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(ImageFrame));
            encoder.Save(fStream);
            fStream.Close();
        }
    }
}
